
<html>
<head>

<link href="../css/style.css" rel="stylesheet" type="text/css">
</head>
<body>

<div id="boxbody" style="Background:url(../img/sfondo.jpg) center no-repeat;">
<div id="boxall" style="top:50px; height: 500px;padding:30px;background:#444;">
	<div class="boxleft" style="top:20px;left:10px; height: 90%;background:#666">
		<div class="boxserach">
			<form name="searchname" action="searchsum.php" method="get">
			<p style="font-size:xx-large;
						font-weight: bold;
						text-align:center;
						color: #F5B007;	"> Inserire nome giocatore da cercare:</p>
			<input style="position:relative;width:250px;height:35px;top:4px;font-size:x-large;" placeholder="Player name" autofocus="autofocus" type="text" name="searchedname">
			<input type="submit" style="width:50px;height:40px;top:0px;" value="CERCA">
			</form>
		</div>
		<div class="boxfreetoplay">
				<?php
	/**
	connessione database
	*/			
	$connessione = mysql_connect("localhost","root","","LOL") or die("Connessione al database fallita");
 	mysql_select_db('LOL',$connessione); 
 	//calcolo totale di champions usati
	$sql="SELECT champion
			FROM week
			where idweek=2";
 	$weekchamp= mysql_query($sql);
		 	if(!$weekchamp)
		 		die("Esequzione della query fallita".mysql_error());
		 	if(mysql_num_rows($weekchamp) == 0){
		 		echo "I dati dei champions devono essere aggiornati<BR>";
		 	}
		 	else{
				echo "<p style=\";font-size:x-large;font-weight: bold;	\">Champion della settimana gratuiti</p>
					<table id=\"weekfree\" ><tr>";
				$nrow=0;
				while($row=mysql_fetch_assoc($weekchamp)){
					if($nrow==4||$nrow==8)
						echo "</tr><tr>";
					echo "<td style=\"width:65px;\"><a href=\"http://127.0.0.1/loldb/php/showskill.php?champion=$row[champion]\"><img src=\"../img/champion/$row[champion].png\"  alt=\"\" /></a></td>
						  <td style=\"text-align:left;width:60px;font-size:large;font-weight: bold;	\"><a href=\"http://127.0.0.1/loldb/php/showskill.php?champion=$row[champion]\">$row[champion]</a></td>";
					$nrow++;
				}
				echo "</tr></table>";
				/**
				 * FINE STAMPA
				 */
			mysql_free_result($weekchamp);
			mysql_close();
		
			/*
			fine connessione
			*/
			}
?> 
		
		</div>
	</div>
	<div class="boxright" style="top:20px;right:10px; height: 90%;background:#666">
		<div class="boxtopplaychamp">
			<?php
	/**
	connessione database
	*/			
	$connessione = mysql_connect("localhost","root","","LOL") or die("Connessione al database fallita");
 	mysql_select_db('LOL',$connessione); 
 	//calcolo totale di champions usati
	$sql="SELECT count(*) as totale
				FROM statistichep";
 	$totale= mysql_query($sql);
 	if(!$totale)
 		die("Esequzione della query fallita".mysql_error());
 	if(mysql_num_rows($totale) == 0){
 		echo "I dati dei champions devono essere aggiornati<BR>";
 	}
 	else {
		 		$totalechamp=mysql_fetch_assoc($totale)['totale'];
		 	
			//if($connessione) echo "connesione stabilita";
		 	$sql="SELECT champion,count(*) as totaleuso
						FROM statistichep
						GROUP BY champion
						ORDER BY count(*) DESC
						LIMIT 5" ;
		 	$topchamp= mysql_query($sql);
		 	if(!$topchamp)
		 		die("Esequzione della query fallita".mysql_error());
		 	if(mysql_num_rows($topchamp) == 0){
		 		echo "I dati dei champions devono essere aggiornati<BR>";
		 	}
		 	else{
				echo "<table id=\"freetable\" ><tr><td style=\"color:GOLD;font-size:x-large\">TOP PLAYED CHAMPIONS</td><tr></table>
		 				<table id=\"freetable\">
		 				<tr><td class=\"intestazione\"></td><td class=\"intestazione\">Champion</td><td class=\"intestazione\">Use Rate</td></tr>";
				while($row=mysql_fetch_assoc($topchamp)){
					echo "<tr><td><a href=\"http://127.0.0.1/loldb/php/showskill.php?champion=$row[champion]\"><img src=\"../img/champion/$row[champion].png\"  alt=\"\" /></a></td>
						  <td><a href=\"http://127.0.0.1/loldb/php/showskill.php?champion=$row[champion]\">$row[champion]</a></td>
						  <td>".(($row['totaleuso']/$totalechamp)*100)."%</td></tr>";
					
				}
				
				/**
				 * FINE STAMPA
				 */
			mysql_free_result($topchamp);
			mysql_close();
		
			/*
			fine connessione
			*/
			}
 	}
?> 
		</div>
	</div>
</div>
</div>
</body>
</html>

<?php
?>

